package com.common.utils;

import java.util.LinkedHashSet;
import java.util.Set;

public class StringUtils {

    /**
     * 去掉字符串中重复的字符串
     * @param splitChar
     * @param str
     * @return
     */
    public static String removeSameString(String str, String splitChar)
    {
        Set<String> mlinkedset = new LinkedHashSet<String>();
        String[] strarray = str.split(splitChar);
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < strarray.length; i++)
        {
            if (!mlinkedset.contains(strarray[i]))
            {
                mlinkedset.add(strarray[i]);
                sb.append(strarray[i] + splitChar);
            }
        }
        //System.out.println(mlinkedset);
        System.out.println(sb.toString());
        //return sb.toString().substring(0, sb.toString().length() - 1);
        return sb.toString();
    }

    /**
     * 去掉重复字符
     * @param s
     * @return
     */
    public static String removeRepeatedChar(String s) {
        if (s == null)
            return s;
        StringBuilder sb = new StringBuilder();
        int i = 0, len = s.length();
        while (i < len) {
            char c = s.charAt(i);
            sb.append(c);
            i++;
            while (i < len && s.charAt(i) == c) {
                i++;
            }
        }
        return sb.toString();
    }

    public static void main(String[] args){
        String  a = "励洁(lijie),彭丽丽(penglili),励洁(lijie),";
        String ret = StringUtils.removeSameString(a,",");
    }
}
